﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using LitJson;
using System;

public class ReadJson : MonoBehaviour {
    private string _ticketStub;

    public string TicketStub
    {
        get
        {
            return _ticketStub;
        }

        set
        {
            _ticketStub = value;
        }
    }

    // Use this for initialization
    void Start () {
        StartCoroutine(JsonWWW("file://"+Application.streamingAssetsPath + "/json.txt"));
	}
  
    IEnumerator JsonWWW(string path)
    {
        Debug.Log(path);
        WWW www = new WWW(path);
        yield return www;
        Debug.Log("Json:"+www.text);
        string jsonData = System.Text.Encoding.UTF8.GetString(www.bytes, 3, www.bytes.Length - 3);  // Skip thr first 3 bytes (i.e. the UTF8 BOM)
        GetJson(jsonData);
    }

    private void GetJson(string str)
    {
        JsonData _jsonData = JsonMapper.ToObject(str);

        _ticketStub = _jsonData["TicketStub"].ToString();
        Debug.Log("TicketStub="+_ticketStub);
    }


}
